//
//  MySatrtCompetionViewController.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/8/16.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "MySatrtCompetionViewController.h"
#import "NOContentView.h"
#import "CompetionInforCell.h"
#import "MatchListModel.h"
@interface MySatrtCompetionViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataArray;
@end

@implementation MySatrtCompetionViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
    [self.dataArray removeAllObjects];
    [self getDataInformationWithShowCurrentpage:@"10"];
    [self createTableViewUI];
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
        // Fallback on earlier versions
    }
}
-(void)createTableViewUI{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 104) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    UIView *view = [[UIView alloc] init];
    self.tableView.tableFooterView = view;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[CompetionInforCell class] forCellReuseIdentifier:@"CompetionInforCell"];

}
#pragma mark -tableview的代理方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CompetionInforCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CompetionInforCell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.dataArray[indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return scaleTopAndBottom(255.f);
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //    MatchListModel *model = self.dataArray[indexPath.row];
    //    SignUpViewController *signupVc = [[SignUpViewController alloc] init];
    //    signupVc.matchID = model.Id;
    //    signupVc.matchStarttime = model.matchStartTime;
    //    [self.navigationController pushViewController:signupVc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [[NSMutableArray alloc] init];
    }
    return _dataArray;
}
-(void)getDataInformationWithShowCurrentpage:(NSString *)showpage{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSString *url = ServerIp@"/matchRecordApp/attendMatchList";
    NSString *sessionId = [[NSUserDefaults standardUserDefaults] objectForKey:@"sessionId"];
    NSDictionary *param = @{@"sessionId":sessionId,@"currentPage":@"1",@"showCount":showpage};
    NSLog(@"%@",param);
    [manager POST:url parameters:param progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSArray *dataArra = jsonDic[@"list"];
        for (NSDictionary *dict in dataArra) {
            NSDictionary *matchDic = dict[@"match"];
            MatchListModel *model = [MatchListModel modelWithDictionary:matchDic];
            [self.dataArray addObject:model];
        }
        if (self.dataArray.count == 0) {
            NOContentView *noconteView = [NOContentView initWithImage:@"订单无数据" AndWithTitile:@"空空如也 赶快参赛吧"];
            noconteView.frame = self.view.bounds;
            [self.view addSubview:noconteView];
        }else{
            [self.tableView reloadData];
        }
        
        NSLog(@"%@",jsonDic);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"失败%@",error);
    }];
    
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
